<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="btn1">点我存cookie</button>
    <button class="btn2">点我获取cookie</button>
    <script>
        //一。存cookie的时候可以手动修改path,/代表最外层，不设置就是默认为当前路径
        document.querySelector('.btn1').onclick=function(){
            document.cookie ="myname=小恒恒;Max-Age=3600;path=/"
        }
        //二。获取cookie时只能获取时只能获取同层或者里层获取外层。外层路径获取里层路径获取不到
        document.querySelector('.btn2').onclick=function(){
            console.log(document.cookie);
        }
    </script>
</body>
</html>